package com.java.auth.controller;

import com.java.auth.service.IndexService;
import com.java.common.utils.JwtHelper;
import com.java.common.utils.R;
import com.java.vo.system.LoginVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import jdk.nashorn.internal.parser.Token;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

@RestController
@Api(tags = "后台登录管理")
@RequestMapping("/admin/user")
public class IndexController {

    @Autowired
    private IndexService indexService;
    @PostMapping("/login")
    public R login(@RequestBody LoginVo loginVo){
//{code: 20000, data: {token: "admin-token"}}
        return indexService.login(loginVo);

    }
    @GetMapping("/info")
    public R info(HttpServletRequest request){
        String token = request.getHeader("token");
        Long userId = JwtHelper.getUserId(token);

        return indexService.info(userId);
    }
    @PostMapping("logout")
    public R logout(){
        return R.ok();
    }

}
